<?PHP
include('config/config.php');
	$conn = mysql_connect($cfg["connection"]["host"], $cfg["connection"]["userName"], $cfg["connection"]["password"]) 
		or die ('Error Cannot Connect to MySQL');
	@mysql_select_db($cfg["connection"]["database"]) or die( "Unable to select database");
	
	$query = "SELECT * FROM item";
	$result = mysql_query($query);
	$items = array();
	while ($item = mysql_fetch_assoc($result, MYSQL_NUM)) $items[]=$item;
//	mkdir("/usr/local/apache/htdocs/admin-panel/generated_files/");
	
	$query = "SELECT curdate() as date";
	$result = mysql_query($query);
	$date = mysql_fetch_array($result);
	$date = $date['date'];
	$filename = "/usr/local/apache/htdocs/admin-panel/generated_files/Inventory_Master_$date.txt";
	$file = fopen($filename, "w");
	
	foreach($items as $item) {
			fwrite($file,"$item[1]:$item[3]:$item[4]:$item[0]:$item[2]:$item[5]:$item[6]:$item[7]\n");
	}
	fclose($file);
?>